import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    hidden: true
  },

  {
    path: '/cms',
    redirect: '/user/list'
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/cms/user/list'),
        meta: { title: '用户管理', icon: 'el-icon-user-solid' }
      }, {
        path: 'detail/:id',
        component: () => import('@/views/cms/user/detail'),
        meta: { title: '用户详情', icon: 'el-icon-user-solid' },
        hidden: true
      }
    ]
  },
  {
    path: '/house',
    component: Layout,
    children: [
      {
        path: 'list',
        component: () => import('@/views/cms/house/list'),
        meta: { title: '房源管理', icon: 'el-icon-school' }
      }, {
        path: 'detail/:id',
        component: () => import('@/views/cms/house/detail'),
        meta: { title: '房源详情', icon: 'el-icon-user-solid' },
        hidden: true
      }
    ]
  },
  // {
  //   path: '/audit',
  //   component: Layout,
  //   name: 'game-manage',
  //   children: [
  //     {
  //       path: 'list',
  //       component: () => import('@/views/cms/house/list'),
  //       meta: { title: '审核管理', icon: 'el-icon-s-claim' }
  //     }
  //   ]
  // },
  {
    path: '/cms/report',
    component: Layout,
    name: 'game-manage',
    children: [
      {
        path: 'list',
        component: () => import('@/views/cms/report/list'),
        meta: { title: '举报管理', icon: 'el-icon-s-check' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true },
  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
